<extend name="common:commonNewerTemplate"/>
<block name="main_content">
    <style>
        .controls input[type=text] {
            width: 60%;
        }
    </style>
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a class="tip-bottom" href="#"
                   data-original-title="Go to Home"><i class="icon-home"></i> 首页</a> <a
                    href="#">商品</a> <a class="current" href="#">sku信息列表</a>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
                            <h5>sku信息</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <form novalidate="novalidate" id="basic_validate"
                                  name="basic_validate" action="#" method="post"
                                  class="form-horizontal">
								<div class="control-group">
	                                <div class="controls">
	                                    <input type="button" value="加载产品信息" class="btn btn-success" id="btn_product_search"/>
	                                </div>
                                </div>


                                <div class="control-group">
                                    <label class="control-label">产品编号:</label>
                                    <div class="controls">
                                        <input type="text" id="product_id" name="product_id"/><span
                                            style="color:red;">*</span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">产品名称:</label>
                                    <div class="controls">
                                        <input type="text" id="product_name" name="product_name"/><span
                                            style="color:red;">*</span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">客户物料号:</label>
                                    <div class="controls">
                                        <input type="text" id="material_no" name="material_no" readonly="readonly"><span
                                            style="color:red;">*</span>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">sku编号:</label>
                                    <div class="controls">
                                        <input type="text" id="sku_id" name="sku_id"/><span style="color:red;">*</span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">sku编码:</label>
                                    <div class="controls">
                                        <input type="text" id="sku_sn" name="sku_sn"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">sku名称:</label>
                                    <div class="controls">
                                        <input type="text" id="sku_name" name="sku_name"><span
                                            style="color:red;">*</span>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">促销信息</label>
                                    <div class="controls">
                                        <input type="text" id="promotion_text" name="promotion_text">
                                    </div>
                                </div>


                                <div class="control-group">
                                    <label class="control-label">商品编号:</label>
                                    <div class="controls">
                                        <input type="text" id="style_id" name="style_id"><span
                                            style="color:red;">*</span>

                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">商品编码:</label>
                                    <div class="controls">
                                        <input type="text" id="style_sn" name="style_sn"><span
                                            style="color:red;">*</span>

                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">商品名称:</label>
                                    <div class="controls">
                                        <input type="text" id="style_name" name="style_name" style="width: 60%"><span
                                            style="color:red;">*</span>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">sku渠道:</label>
                                    <div class="controls">
                                        <select id="sku_channel" name="sku_channel" style="width:62%">
                                            <option value="1">淘宝</option>
                                            <option value="2">京东</option>
                                            <option value="3">官网</option>
                                            <option value="5">英雄会O2O</option>
                                            <option value="6">村淘</option>
                                            <option value="8">线下渠道</option>
                                            <option value="10">VR渠道</option>
                                            <option value="11">四川电信</option>
                                            <option value="13">等级品</option>
                                        </select><span style="color:red;">*</span>
                                    </div>
                                </div>

                            <div class="control-group">
                                <label class="control-label">sku描述性URL:</label>
                                <div class="controls">
                                    <input type="text" id="desc_url" name="desc_url">
                                </div>
                            </div>
                                <!--
                            <div class="control-group">
                                <label class="control-label">sku维度1编号:</label>
                                <div class="controls">
                                    <input type="text" id="sku_dimension_id1" name="sku_dimension_id1">
                                </div>
                            </div>
                         <div class="control-group">
                                <label class="control-label">sku维度1名称:</label>
                                <div class="controls">
                                    <input type="text" id="sku_dimension_name1" name="sku_dimension_name1">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">sku维度1值:</label>
                                <div class="controls">
                                    <input type="text" id="sku_dimension_value1" name="sku_dimension_value1">
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label">sku维度2编号:</label>
                                <div class="controls">
                                    <input type="text" id="sku_dimension_id2" name="sku_dimension_id2">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">sku维度2名称:</label>
                                <div class="controls">
                                    <input type="text" id="sku_dimension_name2" name="sku_dimension_name2">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">sku维度2值:</label>
                                <div class="controls">
                                    <input type="text" id="sku_dimension_value2" name="sku_dimension_value2">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">是否按城市价格销售:</label>
                                <div class="controls">
                                    <select id="is_city_price" name="is_city_price" style="width:220px;">
                                      <option value="0">非</option>
                                      <option value="1">是</option>
                                    </select>
                                </div>
                            </div> -->
                                <div class="control-group">
                                    <label class="control-label">市场价:</label>
                                    <div class="controls">
                                        <input type="text" id="market_price" name="market_price">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">单价:</label>
                                    <div class="controls">
                                        <input type="text" id="sale_price" name="sale_price"><span
                                            style="color:red;">*</span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">优先级:</label>
                                    <div class="controls">
                                        <input type="text" id="priority" name="priority" value="0"
                                               onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                                               onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}">
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">经销商渠道最低限价:</label>
                                    <div class="controls">
                                        <input type="text" id="dealer_min_limit_price" name="dealer_min_limit_price"><span
                                            style="color:red;">*</span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">退款价格:</label>
                                    <div class="controls">
                                        <input type="text" id="return_price" name="return_price"><span
                                            style="color:red;">*</span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">个人提成金额:</label>
                                    <div class="controls">
                                        <input type="text" id="person_commission_amount"
                                               name="person_commission_amount">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">经销商提成金额</label>
                                    <div class="controls">
                                        <input type="text" id="dealer_commission_amount"
                                               name="dealer_commission_amount">
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">是否支持返点</label>
                                    <div class="controls">
                                        <select type="text" id="is_rebate" name="is_rebate"  style="width: 62%">
                                            <option value="0">否</option>
                                            <option value="1" selected>是</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">是否是礼品</label>
                                    <div class="controls">
                                        <select type="text" id="is_gift" name="is_gift"  style="width: 62%">
                                            <option value="0" selected>否</option>
                                            <option value="1">是</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">图片:</label>
                                    <div class="controls">
                                        <input type="text" id="image" name="image">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">图片集合</label>
                                    <div class="controls">
                                        <input type="text" id="image_list" name="image_list">
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">状态</label>
                                    <div class="controls">
                                        <select id="status" name="status" style="width: 62%;">
                                            <option value="1">有效</option>
                                            <option value="0">无效</option>
                                        </select>
                                    </div>
                                </div>
                                
                                <div class="control-group">
	                            	<label class="control-label">会员服务<span class="required-tips">*</span></label>
	                                <div class="controls">
	                                    <select id="referent_id" name="referent_id"  style="width: 62%" >
	                                    	<option value="0">不选择</option>
	                                    	<foreach name="vip_bag_lst" item="itm" key="key">
												<option value="{$itm.id}">{$itm.invoice_name}</option>
											</foreach >
	                                	</select>
	                            	</div>
	                            </div>
	                            
	                            <div class="control-group">
                                    <label class="control-label">开票名称<span class="required-tips">*</span></label>
                                    <div class="controls">
                                        <input type="text" id="invoice_title" name="invoice_title" value="{$product_split.invoice_title}" maxlength="30">
                                    </div>
                                </div>

                                <div class="control-group">
                                    <a id="btn_addSku" class="btn btn-success">新增sku商品</a>
                                    <a id="btn_resetSku" href="/sku/addSku" class="btn btn-danger">重置</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>


<block name="js_content">
    <script src="/Public/js/layer/layer.js" type="text/javascript"></script>
    <script type="text/javascript">
        //新增商品
        $('#btn_addSku').bind('click', function () {

            var sku_channel_name = encodeURIComponent($('#sku_channel').find("option:selected").text());
            var condition = $('#basic_validate').serialize();
            condition += "&sku_channel_name=" + sku_channel_name;
            $.ajax({
                type: 'post',
                url: '/AjaxService/center/sku/addSku',
                data: condition,
                dataType: 'json',
                async: false,
                success: function (data) {
                    if (data.IsSuccess == 0) {
                        alert(data.ErrorMsg);
                        return;
                    } else {
                        alert('操作成功');
                    }
                },
                error: function (e, err_name, err_text) {

                }
            });

        });


        $('#btn_style_id').bind('click', function () {

            var result = SkuService.GetStyleID();
            $('#style_id').val(result['Result']);


        });

        $('#btn_product_id').bind('click', function () {

            var result = SkuService.GetProductID();
            $('#product_id').val(result['Result']);


        });


        function setChannelName(obj) {

            var channel_name = $(obj).find("option:selected").text();
            $('#sku_channel_name').val(channel_name);
        }


    </script>
    <script type="text/javascript">

        SkuPageInfo = {

            'BindEvent': function () {
                $('#btn_product_search').bind('click', function () {
                    SkuPageInfo.SearchProduct();
                });
/*
                $('#sku_channel').on('change', function () {
                    SkuPageInfo.validateProduct();
                });*/
            },
            'SearchProduct': function () {

                var product_id = $('#product_id').val();
                var product_name = encodeURIComponent($('#product_name').val());
                var material_no = $('#material_no').val();
                /* if(product_id =='' && product_name==''){
                 alert('产品编号或者产品名称不能为空');
                 return false;
                 }
                 */
                layer.open({
                    type: 2,
                    title: '产品搜索',
                    skin: 'whaley-layui-search',
                    fix: true,
                    shadeClose: true,
                    maxmin: true,
                    area: ['1000px', '600px'],
                    content: '/sku/productinfosearch?product_id=' + product_id + '&product_name=' + product_name + '&material_no=' + material_no,
                    end: function () {
                    	//layer.msg('完成选择', {icon: 0});
                        //layer.tips('完成选择', '#photosDemo', {tips: 1})
                    }
                });
            },


            'BuildPage': function (data) {
            	//填充数据
            	var product = data.Result.product;
                $('#product_id').val(product.product_id);
                $('#product_name').val(product.product_name);
                $('#material_no').val(product.material_no);
                $('#sku_name').val(product.product_name);
                $('#style_name').val(product.product_name);
                $('#image').val(product.image);
                $('#image_list').val(product.image_list);
                $('#invoice_title').val(product.invoice_title);
                
                $('#style_id').val(SkuService.GetStyleID()['Result']);
                $('#style_sn').val($('#style_id').val());
                //style_id
                var sku_val = SkuService.GetSkuID()['Result'];
                $('#sku_id').val(sku_val);
                $('#sku_sn').val(sku_val);
                //skuid
				//SkuPageInfo.validateProduct();
            },

        }

        $(document).ready(function () {
            SkuPageInfo.BindEvent();
            $('#referent_id').select2('val',{$product_split.referent_id});
        });

    </script>

</block>